Skip to content

[3.0][Testing] Anchor the canonical path test to the root the platform actually uses - #9600

Merged
jdarwood007 merged 1 commit into
SimpleMachines:release-3.0from
albertlast:3.0/sapitest-windows-root
Aug 31, 2026
Merged

[3.0][Testing] Anchor the canonical path test to the root the platform actually uses#9600
jdarwood007 merged 1 commit into
SimpleMachines:release-3.0from
albertlast:3.0/sapitest-windows-root

Conversation

@albertlast

Copy link
Copy Markdown
Collaborator

Description

SapiTest::testCanonicalPathResolvesDotSegments() asserted a POSIX-only result, so it failed on Windows with C:\a\c where it expected /a/c.

The production code is right. On Windows, canonicalPath('/a/./b/../c') normalises the separators and then falls into the "Windows relative path" branch: a path that starts at the root but names no drive is rooted on the current drive, so getcwd()'s drive letter is prepended. C:\a\c is the correct canonical form of \a\c there, and realpath() would say the same thing. The test simply baked in the shape an absolute path has on one platform.

Naming the root in the path under test takes the DOS-style-path branch on Windows instead, so the result no longer depends on which drive the checkout happens to sit on:

$root = DIRECTORY_SEPARATOR === '/' ? '' : 'C:';
$sep = DIRECTORY_SEPARATOR;

$this->assertSame($root . $sep . 'a' . $sep . 'c', Sapi::canonicalPath($root . '/a/./b/../c', false, false));
$this->assertSame($root . $sep . 'a', Sapi::canonicalPath($root . '/a/b/..', false, false));

The assertion is then about the dot segments, which is what the test is named for, rather than about the machine running it.

Verified by extracting the function body, substituting \ for DIRECTORY_SEPARATOR and running it: the old assertions produce C:\a\c and C:\a exactly as reported, and the new ones hold. The suite is green on Linux, and composer lint is clean.

The rest of tests/Unit/ has no other case of this. The remaining '/...' literals are URL routes rather than file paths, and LangTest compares canonicalPath() output against canonicalPath() output, so both sides move together.

Issues References (Fixes|Related|Closes)

  1. Fixes SapiTest fails on Windows #9595

An absolute path is rooted differently on each platform: a leading separator
on POSIX, a drive letter on Windows. Naming the root in the path under test
keeps the assertion about the dot segments rather than about the machine the
suite happens to run on.

Signed-off-by: albertlast <mathiaspapealbert@hotmail.com>
@jdarwood007 jdarwood007 added this to the 3.0 Alpha 5 milestone Aug 31, 2026
@jdarwood007
jdarwood007 merged commit 28227aa into SimpleMachines:release-3.0 Aug 31, 2026
7 checks passed
@live627

live627 commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

This assertion should probably be a regex so that it can accept any drive letter.

@albertlast

Copy link
Copy Markdown
Collaborator Author

Agreed, and #9605 does that.

The hardcoded C: was not actually a machine assumption — the drive comes from the input, so the DOS-style branch is taken and the CI runner passed it on D: — but it reads like one, and worse, it meant nothing was covering the branch that broke: on Windows a path that starts at the root but names no drive is rooted on the current one.

So rather than a regex I split the two behaviours. Resolving dot segments has nothing to do with the root, so that test uses a relative path and asserts the whole result exactly. What the root is gets its own test, reading the drive from the working directory. No letter is named anywhere, and the branch that caused #9595 is now under test.

A regex would also have removed the letter; I went with the exact assertion because the expected value is a specific drive rather than any drive, and it gives a diff on failure. Say the word if you would rather have the pattern.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SapiTest fails on Windows

3 participants